package com.heima.wemedia.controller;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.NewsAuthDTO;
import com.heima.model.wemedia.dtos.WmNewsDTO;
import com.heima.model.wemedia.dtos.WmNewsPageReqDTO;
import com.heima.model.wemedia.dtos.WmUpOrDownDTO;
import com.heima.model.wemedia.pojos.WmNews;
import com.heima.wemedia.service.WmNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/news")
public class WmNewsController {

    @Autowired
    WmNewsService wmNewsService;
    @PostMapping("down_or_up")
    public ResponseResult downOrUp(@RequestBody WmUpOrDownDTO dto){
        return wmNewsService.upOrDown(dto);

    }
    /**
     * 修改文章
     * @param wmNews
     * @return
     */
    @PutMapping("/update")
    public ResponseResult updateWmNews(@RequestBody WmNews wmNews) {
        wmNewsService.updateById(wmNews);
        return ResponseResult.okResult();
    }


    /**
     * 文章审核成功
     * @param dto
     * @return
     */

    @PostMapping("/auth_pass")
    public ResponseResult authPass(@RequestBody NewsAuthDTO dto) {
        return wmNewsService.updateStatus((short)4,dto);
    }

    /**
     * 文章审核失败
     * @param dto
     * @return
     */

    @PostMapping("/auth_fail")
    public ResponseResult authFail(@RequestBody NewsAuthDTO dto) {
        return wmNewsService.updateStatus((short)2,dto);
    }


    /**
     * 查询文章详情
     * @param id
     * @return
     */
    @GetMapping("/one_vo/{id}")
    public ResponseResult findWmNewsVo(@PathVariable("id") Integer id) {
        return wmNewsService.findWmNewsVo(id);

    }
    /**
     * 查询文章列表
     * @param dto
     * @return
     */
    @PostMapping("/list_vo")
    public ResponseResult findList(@RequestBody NewsAuthDTO dto) {
        return wmNewsService.findList(dto);

    }


    @PostMapping("list")
    public ResponseResult list(@RequestBody WmNewsPageReqDTO dto){
        return wmNewsService.findList(dto);

    }
    @PostMapping("submit")
    public ResponseResult submit(@RequestBody WmNewsDTO dto){
        return wmNewsService.submit(dto);
    }

    @GetMapping("/one/{id}")
    public ResponseResult getOneById(@PathVariable("id") Integer id){
        return wmNewsService.getOneById(id);
    }

    @GetMapping("del_news/{id}")
    public ResponseResult deleteOneById(@PathVariable("id") Integer id){
        return wmNewsService.deleteOneById(id);
    }
    @PostMapping ("del_news/down_or_up}")
    public ResponseResult news_down_or_up(@RequestBody WmNewsDTO dto ){
        return wmNewsService.news_down_or_up(dto);
    }

}
